
package com.idealighter.game.games.errentexaspoker.handler;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.dictionary.domain.ErrentexaporkerRoomDomain;
import com.idealighter.game.gamehall.dto.SeatInfo;
import com.idealighter.game.games.errentexaspoker.ErrenTexaspokerPlayer;
import com.idealighter.game.games.errentexaspoker.message.ReqDealCardOverMsg;
import com.idealighter.game.games.errentexaspoker.message.ResDealCardsMsg;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;
import com.idealighter.utils.code.RandCodeUtil;

import java.util.concurrent.TimeUnit;


@ResMsgHandler(515207)
public class ResDealCardsHandler implements ResMessageHandler {


  @Override
  public void action(Player player, ResMessage message) {
    ResDealCardsMsg msg = (ResDealCardsMsg) message;
    ErrenTexaspokerPlayer texaspokerPlayer = (ErrenTexaspokerPlayer) player;
    SeatInfo seatInfo = texaspokerPlayer.seat(player.playerId);
    ErrentexaporkerRoomDomain roomDomain = ((ErrenTexaspokerPlayer) player).roomDomain;
    int minOne = roomDomain.getMinOne();
    if (seatInfo != null && seatInfo.getOrder() == msg.getSmallBind()) {
      texaspokerPlayer.betRecord.add((long) minOne / 2);
      texaspokerPlayer.curBet = minOne / 2;
    }
    if (seatInfo != null && seatInfo.getOrder() == msg.getBinBind()) {
      texaspokerPlayer.betRecord.add((long) minOne);
      texaspokerPlayer.curBet = minOne;
    }
    texaspokerPlayer.cardList.addAll(msg.getCards());
    texaspokerPlayer.setHandCard(msg.getCards());
    player.schedule(() -> player.sendMsg(new ReqDealCardOverMsg()), RandCodeUtil.random(3, 5),
        TimeUnit.SECONDS);
  }
}
